package backend.ro.msg.gillardon.businesstripplanner.hotel.parser;

import java.io.IOException;
import java.io.Serializable;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class CommundoHotel implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private final String[] informations;

    public CommundoHotel() throws IOException {
	System.setProperty("http.proxyHost", "proxy.msg.de");
	System.setProperty("http.proxyPort", "3128");
	Document doc = Jsoup
		.connect(
			"http://www.commundo-tagungshotels.de/en/ismaning/accomodation-ismaning/rates-ismaning.html")
		.timeout(10 * 1000).get();
	Element div = doc.getElementById("cbox");
	Elements paragraphs = div.getElementsByClass("bodytext");
	Element firstP = paragraphs.first();
	String pricesInformation = firstP.text();
	this.informations = pricesInformation.split(" ");
    }

    public double getSingleRoomPriceWeek() {
	return Double.parseDouble(replace(this.informations[13]));
    }

    public double getSingleRoomPriceWeekend() {
	return Double.parseDouble(replace(this.informations[15]));
    }

    public double getDoubleRoomPriceWeek() {
	return Double.parseDouble(replace(this.informations[29]));
    }

    public double getDoubleRoomPriceWeekend() {
	return Double.parseDouble(replace(this.informations[31]));
    }

    public String getCurrency() {
	return this.informations[12];
    }

    public String replace(final String value) {
	return value.replaceAll("[^\\d.]", "");
    }

}
